package com.hxz.graduationdesign.controller;

import com.hxz.graduationdesign.base.response.JsonResult;
import com.hxz.graduationdesign.base.response.StatusCode;
import com.hxz.graduationdesign.pojo.vo.DanmuVo;
import com.hxz.graduationdesign.service.IDanmuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/v1/danmu/")
public class DanmuController {

    @Autowired
    private IDanmuService danmuService;

    @PostMapping("query/{bv}")
    public JsonResult queryDanmu(@PathVariable String bv){
        log.debug("查询弹幕bv："+bv);
        List<DanmuVo> query = danmuService.query(bv);
        if (query==null){
            return new JsonResult(StatusCode.DANMU_ADD_FAILED,null);
        }else if(query.isEmpty()){
            return new JsonResult(StatusCode.DANMU_QUERY_NULL,null);
        }else {
            return JsonResult.ok(query);
        }

    }

    @PostMapping("update/{bv}")
    public JsonResult updateDanmu(@PathVariable String bv){
        log.debug("更新弹幕bv："+bv);


        List<DanmuVo> query = danmuService.update(bv);
        if (query==null){
            return new JsonResult(StatusCode.DANMU_ADD_FAILED,null);
        }else if(query.isEmpty()){
            return new JsonResult(StatusCode.DANMU_QUERY_NULL,null);
        }else {
            return JsonResult.ok(query);
        }

    }

    @PostMapping("segmenter/{bv}")
    public JsonResult getSegmenter(@PathVariable String bv){
        Map<String, Integer> segmenter = danmuService.segmenter(bv);

        return JsonResult.ok(segmenter);
    }

    @PostMapping("emo/{bv}")
    public JsonResult geyEmo(@PathVariable String bv){
        Map<String, Integer> emo = danmuService.emo(bv);
        return JsonResult.ok(emo);
    }

}
